import { Config } from "../../config/Config";
import { ErrorCode } from "../../config/ErrorCode";
import { ServerConfig } from "../../config/ServerConfig";
import { ProtoServerConfig } from "../socketserver/protocol/ProtoServerConfig";
import { SocketMsg } from "../socketserver/socket/SocketMsg";
import { Logger } from "../utils/Logger";
import { WebSocketClient } from "./WebSocketClient";
import { WebSocketClientManager } from "./WebSocketClientManager";

export class SocketClientReqManager {

    public static instance: SocketClientReqManager = new SocketClientReqManager();

    public onSocketMsg(proto_name: string, data: object) {
    }

    public async req_server_login(serverConfig: ServerConfig) {
        let data: object = {
            "protoName": ProtoServerConfig.req_server_login,
            "account": Config.serverType + "-" + ServerConfig.nowServerConfig.id,
        }
        let client: WebSocketClient = WebSocketClientManager.instance.getWebSocketClientByServerConfig(serverConfig);
        if (!client.account) {
            Logger.log("req_server_login==", data);
            let respData = await client.sendDataAsync(data);
            if (respData["code"] == ErrorCode.Code.Suc) {
                client.account = data["account"]
            }
            Logger.log("req_server_login resp=", respData)
        }
    }

    public async req_server_set_server_status(status: number, serverConfig: ServerConfig) {
        let data: object = {
            "protoName": ProtoServerConfig.req_server_set_server_status,
            "status": status
        }
        let client: WebSocketClient = WebSocketClientManager.instance.getWebSocketClientByServerConfig(serverConfig);
        let respData = await client.sendDataAsync(data);
        return respData
    }


    public async req_server_is_in_server(account: string, serverConfig: ServerConfig) {
        let data: object = {
            "protoName": ProtoServerConfig.req_server_is_in_server,
            "account": account
        }
        let client: WebSocketClient = WebSocketClientManager.instance.getWebSocketClientByServerConfig(serverConfig);
        Logger.log("req_server_is_in_server==", data);
        let respData = await client.sendDataAsync(data);
        Logger.log("req_server_is_in_server resp=", respData)
        return respData
    }

    public async req_server_is_user_online(userid: number, serverConfig: ServerConfig) {
        let data: object = {
            "protoName": ProtoServerConfig.req_server_is_user_online,
            "userid": userid
        }
        let client: WebSocketClient = WebSocketClientManager.instance.getWebSocketClientByServerConfig(serverConfig);
        Logger.log("req_server_is_user_online==", data);
        let respData = await client.sendDataAsync(data);
        Logger.log("req_server_is_user_online resp=", respData)
        return respData
    }

    public async req_server_onlie_club(clubid: number, serverConfig: ServerConfig) {
        let data: object = {
            "protoName": ProtoServerConfig.req_server_onlie_club,
            "clubid": clubid,
        }
        let client: WebSocketClient = WebSocketClientManager.instance.getWebSocketClientByServerConfig(serverConfig);
        let respData = await client.sendDataAsync(data);
        Logger.log("req_server_onlie_club resp=", respData)
        return respData
    }

    public async req_server_notify_delete_club_user(clubid: number, userid: number, serverConfig: ServerConfig) {
        let data: object = {
            "protoName": ProtoServerConfig.req_server_notify_delete_club_user,
            "clubid": clubid,
            "userid": userid
        }
        let client: WebSocketClient = WebSocketClientManager.instance.getWebSocketClientByServerConfig(serverConfig);
        let respData = await client.sendDataAsync(data);
        Logger.log("req_server_notify_delete_club_user resp=", respData)
        return respData
    }

    public async req_server_notify_set_club_quanxian(clubid: number, userid: number, quanxian: string, serverConfig: ServerConfig) {
        let data: object = {
            "protoName": ProtoServerConfig.req_server_notify_set_club_quanxian,
            "clubid": clubid,
            "userid": userid,
            "quanxian": quanxian
        }
        let client: WebSocketClient = WebSocketClientManager.instance.getWebSocketClientByServerConfig(serverConfig);
        let respData = await client.sendDataAsync(data);
        Logger.log("req_server_notify_set_club_quanxian resp=", respData)
        return respData
    }

    public async req_server_notify_club_freeze(clubid: number, userid: number, user_state: number, serverConfig: ServerConfig) {
        let data: object = {
            "protoName": ProtoServerConfig.req_server_notify_club_freeze,
            "clubid": clubid,
            "userid": userid,
            "user_state": user_state
        }
        let client: WebSocketClient = WebSocketClientManager.instance.getWebSocketClientByServerConfig(serverConfig);
        let respData = await client.sendDataAsync(data);
        Logger.log("req_server_notify_club_freeze resp=", respData)
        return respData
    }

    public async req_server_notify_set_club_admin(clubid: number, userid: number, actor: number, quanxian: string, serverConfig: ServerConfig) {
        let data: object = {
            "protoName": ProtoServerConfig.req_server_notify_set_club_quanxian,
            "clubid": clubid,
            "userid": userid,
            "actor": actor,
            "quanxian": quanxian
        }
        let client: WebSocketClient = WebSocketClientManager.instance.getWebSocketClientByServerConfig(serverConfig);
        let respData = await client.sendDataAsync(data);
        Logger.log("req_server_notify_set_club_quanxian resp=", respData)
        return respData
    }

    public async req_server_insertRoomTemplateModel(serverConfig: ServerConfig) {
        let data: object = {
            "protoName": ProtoServerConfig.req_server_insertRoomTemplateModel,
        }
        let client: WebSocketClient = WebSocketClientManager.instance.getWebSocketClientByServerConfig(serverConfig);
        client.sendDataAsync(data);
    }

    public async req_server_deleteRoomTemplateModel(id: number, serverConfig: ServerConfig) {
        let data: object = {
            "protoName": ProtoServerConfig.req_server_deleteRoomTemplateModel,
            "id": id,
        }
        let client: WebSocketClient = WebSocketClientManager.instance.getWebSocketClientByServerConfig(serverConfig);
        client.sendDataAsync(data);
    }

   
   

    public async req_server_deleteRoom(room_id: number, serverConfig: ServerConfig) {
        let data: object = {
            "protoName": ProtoServerConfig.req_server_deleteRoom,
            "room_id": room_id,
        }
        Logger.log("req_server_deleteRoom", data)
        let client: WebSocketClient = WebSocketClientManager.instance.getWebSocketClientByServerConfig(serverConfig);
        client.sendDataAsync(data);
    }


    public async req_server_notify_update_gems(userid: number, serverConfig: ServerConfig) {
        let data: object = {
            "protoName": ProtoServerConfig.req_server_notify_update_gems,
            "userid": userid,
        }
        // Logger.log("req_server_notify_update_gems", data)
        let client: WebSocketClient = WebSocketClientManager.instance.getWebSocketClientByServerConfig(serverConfig);
        client.sendDataAsync(data);
    }

    public async req_server_notify_update_coins(userid: number, serverConfig: ServerConfig) {
        let data: object = {
            "protoName": ProtoServerConfig.req_server_notify_update_coins,
            "userid": userid,
        }
        // Logger.log("req_server_notify_update_gems", data)
        let client: WebSocketClient = WebSocketClientManager.instance.getWebSocketClientByServerConfig(serverConfig);
        client.sendDataAsync(data);
    }

    public async req_server_notify_update_meili(userid: number, serverConfig: ServerConfig) {
        let data: object = {
            "protoName": ProtoServerConfig.req_server_notify_update_meili,
            "userid": userid,
        }
        // Logger.log("req_server_notify_update_gems", data)
        let client: WebSocketClient = WebSocketClientManager.instance.getWebSocketClientByServerConfig(serverConfig);
        client.sendDataAsync(data);
    }

    public async req_server_notify_update_lv(userid: number, serverConfig: ServerConfig) {
        let data: object = {
            "protoName": ProtoServerConfig.req_server_notify_update_lv,
            "userid": userid,
        }
        // Logger.log("req_server_notify_update_gems", data)
        let client: WebSocketClient = WebSocketClientManager.instance.getWebSocketClientByServerConfig(serverConfig);
        client.sendDataAsync(data);
    }

    public async req_server_notify_update_invite(userid: number, serverConfig: ServerConfig) {
        let data: object = {
            "protoName": ProtoServerConfig.req_server_notify_update_invite,
            "userid": userid,
        }
        // Logger.log("req_server_notify_update_gems", data)
        let client: WebSocketClient = WebSocketClientManager.instance.getWebSocketClientByServerConfig(serverConfig);
        client.sendDataAsync(data);
    }

    public async req_server_notify_update_img(userid: number, imgurl: string, upload_pic_type: number, serverConfig: ServerConfig) {
        let data: object = {
            "protoName": ProtoServerConfig.req_server_notify_update_img,
            "userid": userid,
            "imgurl": imgurl,
            "upload_pic_type": upload_pic_type,
        }
        // Logger.log("req_server_notify_update_gems", data)
        let client: WebSocketClient = WebSocketClientManager.instance.getWebSocketClientByServerConfig(serverConfig);
        client.sendDataAsync(data);
    }


}